import java.util.Scanner;

public class ATM {
    public static void main(String[] args) {
        User user = new User();
        String curPwd = user.getPassword();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入您的密码");
        int i = 0;
        while (i < 3) {
            String pwd = scanner.next();

            if (pwd.equals(user.getPassword())) {
                System.out.println("欢迎登陆");
                break;
            }
            i++;
            if ((3 - i) <= 0) {
                System.out.println("密码验证失败三次,强制退出");
                return;
            }
            System.out.println("密码错误还剩" + (3 - i) + "次数");
        }

        boolean flag = true;
        System.out.println("功能列表:");
        while (flag) {
            if (!user.getPassword().equals(curPwd)) {

                i = 0;
                while (i < 3) {
                    System.out.println("密码已经变更,请输入新密码:");
                    String pwd = scanner.next();

                    if (pwd.equals(user.getPassword())) {
                        System.out.println("欢迎登陆");
                        curPwd = pwd;
                        break;
                    }
                    i++;
                    if ((3 - i) <= 0) {
                        System.out.println("密码验证失败三次,强制退出");
                        return;
                    }
                    System.out.println("密码错误还剩" + (3 - i) + "次数");
                }
            }
            System.out.println("主菜单");
            System.out.println("1.查询账户\n" + "2.取款\n" + "3.存款\n" + "4.修改密码\n" + "5.退出\n");
            System.out.println("请输入你的选择:");
            String next = scanner.next();
            switch (next) {
                case "查询账户":
                    user.select();
                    break;
                case "取款":
                    System.out.println("请输入取款金额");
                    int num = scanner.nextInt();
                    user.withDraw(num);
                    break;
                case "存款":
                    System.out.println("请输入存款金额");
                    num = scanner.nextInt();
                    user.addMoney(num);
                    break;
                case "修改密码":
                    System.out.println("请输入新密码");
                    String newPwd = scanner.next();
                    user.changePwd(newPwd);
                    break;
                case "退出":
                    flag = false;
                    break;
            }

        }

        System.out.println("ATM已经退出");

    }


}

class User {
    private String password = "123456";
    private int money = 100000;

    public User() {
        this.password = password;
        this.money = money;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getMoney() {
        return money;
    }

    public void setMoney(int money) {
        this.money = money;
    }

    //查询
    public void select() {
        System.out.println("你的账户余额:" + this.getMoney() + "元");
        System.out.println();
    }

    //取款
    public void withDraw(int num) {
        if (money - num < 0) {
            System.out.println("余额不足");
        } else {
            money = money - num;
            System.out.println("您本次取得" + num + "元");
        }
        System.out.println();
    }

    //存款
    public void addMoney(int num) {
        if (num < 0) {
            return;
        }
        money = money + num;
        System.out.println("本次存款" + num + "元");
        System.out.println();
    }

    //修改密码
    public void changePwd(String newPwd) {
        password = newPwd;
        System.out.println("您的密码已经修改");
    }
}
